package csc.fresher.commons;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

import csc.fresher.dao.AccountHasInterestRateDao;
import csc.fresher.dao.CustomerAccountDao;
import csc.fresher.dao.PeriodTypeDao;
import csc.fresher.entity.CustomerAccount;
import csc.fresher.entity.SavingAccount;
import csc.fresher.entity.SavingAccountHasInterestRate;
import csc.fresher.service.SavingAccountService;
import csc.fresher.service.SavingTransactionService;

public class ScheduleUpdate {

	@Autowired
	SavingAccountService savingAccountService;

	@Autowired
	SavingTransactionService savingTransactionService;

	@Autowired
	AccountHasInterestRateDao accountHasInterestRateDao;

	@Autowired
	PeriodTypeDao periodTypeDao;

	CustomerAccountDao customerAccountDao = null;

	private List<CustomerAccount> savingAccounts;

	// @Scheduled(cron = "0 0 0 * * ?")
	@Scheduled(fixedDelay = 6000*10000)
	public void updateSavingInterestRate() {
		if (savingAccountService != null) {
			savingAccounts = savingAccountService
					.getSavingAccountsIsRepeatable();
			if (savingAccounts != null) {
				System.out.println(savingAccounts.size());
				SavingAccountHasInterestRate accountHasInterestRate = null;
				for (CustomerAccount c : savingAccounts) {
					accountHasInterestRate = accountHasInterestRateDao
							.getInterestRateByAccountNumberID(c
									.getAccountNumber());
					savingAccountService.updatePeriod((SavingAccount) c);
					System.out.println(c.getAccountBalance());
				}
			} else {
				System.out.println("savingaccount null");
			}
		} else {
			System.out.println("savingAccountService is null");
		}

	}
}
